<?php
/**
 * Bair Image Info Class
 *
 * @package Bair
 */
class Bair_Image_Info
{
	protected $width;
	protected $height;
	protected $type;
	protected $file;
	protected $options = array();
	
	public function __construct($width = null, $height = null, $type = null, $file = null, array $options = array())
	{
		if( $width !== null )
			$this->setWidth($width);
		
		if( $height !== null )
			$this->setHeight($height);
		
		if( $type !== null )
			$this->setType($type);
		
		if( $file !== null )
			$this->setFile($file);
		
		$this->setOptions($options);
	}
	
	public function getWidth()
	{
		return $this->width;
	}
	
	public function getHeight()
	{
		return $this->height;
	}
	
	public function getType()
	{
		return $this->type;
	}
	
	public function getFile()
	{
		return $this->file;
	}
	
	public function getOptions()
	{
		return $this->options;
	}
	
	public function getOption($name, $return = null)
	{
		if( isset($this->options[strtolower($name)]) )
			return $this->options[strtolower($name)];
		else
			return $return;
	}
	
	/**
	 * @param int $width
	 * @return Bair_Image_Info
	 */
	public function setWidth($width)
	{
		$this->width = (int)$width;
		
		return $this;
	}
	
	/**
	 * @param int $height
	 * @return Bair_Image_Info
	 */
	public function setHeight($height)
	{
		$this->height = (int)$height;
		
		return $this;
	}
	
	/**
	 * @param string $type
	 * @return Bair_Image_Info
	 */
	public function setType($type)
	{
		if( !in_array($type, array(Bair::JPG, Bair::GIF, Bair::PNG)) )
			throw new Bair_Exception("Invalid Type '$type'");
		
		$this->type = $type;
		
		return $this;
	}
	
	/**
	 * @param string $file
	 * @return Bair_Image_Info
	 */
	public function setFile($file)
	{
		$this->file = (string)$file;
		
		return $this;
	}
	
	public function setOptions(array $options)
	{
		foreach( $options as $key => $value )
		{
			$this->setOption($key, $value);
		}
		
		return $this;
	}
	
	public function setOption($name, $value)
	{
		$this->options[strtolower($name)] = $value;
		
		return $this;
	}
}